﻿#include "filui.h"

#include <QObject>
#include <QQmlEngine>
#include <QDebug>

#include "FpsItem.h"
#include "filframeless.h"
#include "filrectangle.h"
#include "filtablemodel.h"
#include "filtablesortproxymodel.h"
#include "../helper/filtools.h"
#include "../helper/network.h"
#include "../theme/filtheme.h"
#include "../theme/filtextstyle.h"
#include "../theme/filcolors.h"
#include "../common/FilIconDef.h"
#include "../common/def.h"

const char * FilUI::_uri = "FilUI";

FilUI::FilUI(QObject *parent)
    : QObject{parent}
{}

void FilUI::initializeEngine(QQmlEngine *engine, [[maybe_unused]] const char *uri) {
    Q_UNUSED(engine)
}

void FilUI::registerTypes(QQmlEngine *engine)
{
    initializeEngine(engine, _uri);
    registerTypes(_uri);
}

void FilUI::registerTypes(const char *uri)
{
    int major = _major;
    int minor = _minor;

    //@uri FilUI
    qmlRegisterType<FpsItem>                    (uri, major, minor, "FpsItem");
    qmlRegisterType<NetworkCallable>            (uri, major, minor, "NetworkCallable");
    qmlRegisterType<NetworkParams>              (uri, major, minor, "NetworkParams");
    qmlRegisterType<FilFrameless>               (uri, major, minor, "FilFrameless");
    qmlRegisterType<FilTableModel>              (uri, major, minor, "FilTableModel");
    qmlRegisterType<FilRectangle>               (uri, major, minor, "FilRectangle");
    qmlRegisterType<FilTableSortProxyModel>     (uri, major, minor, "FilTableSortProxyModel");

    qmlRegisterUncreatableMetaObject            (NetworkType::staticMetaObject, uri, major, minor,
                                                "NetworkType", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (FilIcons::staticMetaObject, uri, major, minor,
                                                "FilIcons", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (FilPageType::staticMetaObject, uri, major, minor,
                                                "FilPageType", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (FilSheetType::staticMetaObject, uri, major, minor,
                                                "FilSheetType", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (FilContentDialogType::staticMetaObject, uri, major, minor,
                                                "FilContentDialogType", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (FilWindowType::staticMetaObject, uri, major, minor,
                                                "FilWindowType", "Access to enums & flags only");
    qmlRegisterUncreatableMetaObject            (NetworkProxyType::staticMetaObject, uri, major, minor,
                                                "NetworkProxyType", "Access to enums & flags only");


    qmlRegisterSingletonType(QUrl("qrc:/qml/global/TourTools.qml"), uri, major, minor, "TourTools");
    qmlRegisterSingletonType(QUrl("qrc:/qml/controls/FilEventBus.qml"), uri, major, minor, "FluEventBus");
    qmlRegisterSingletonType<FilColors>(uri, major, minor, "FilColors",
                                        [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
                                            Q_UNUSED(scriptEngine)
                                            QObject *instance = FilColors::getInstance();
                                            engine->setObjectOwnership(instance, QQmlEngine::CppOwnership);
                                            return instance;
                                        });
    qmlRegisterSingletonType<FilTheme>(uri, major, minor, "FilTheme",
                                       [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
                                           Q_UNUSED(scriptEngine)
                                           QObject *instance = FilTheme::getInstance();
                                           engine->setObjectOwnership(instance, QQmlEngine::CppOwnership);
                                           return instance;
                                       });
    qmlRegisterSingletonType<FilTools>(uri, major, minor, "FilTools",
                                       [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
                                           Q_UNUSED(scriptEngine)
                                           QObject *instance = FilTools::getInstance();
                                           engine->setObjectOwnership(instance, QQmlEngine::CppOwnership);
                                           return instance;
                                       });
    qmlRegisterSingletonType<FilTextStyle>(uri, major, minor, "FilTextStyle",
                                           [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
                                               Q_UNUSED(scriptEngine)
                                               QObject *instance = FilTextStyle::getInstance();
                                               engine->setObjectOwnership(instance, QQmlEngine::CppOwnership);
                                               return instance;
                                           });
}


